package io.renren.modules.jxgkphone.controller;


import io.renren.RandomString;
import io.renren.modules.jxgk.service.ElectiveCourseService;
import io.renren.modules.jxgkphone.entity.StudentInfo;
import io.renren.modules.jxgkphone.entity.TeacherUser;
import io.renren.modules.jxgkphone.service.StuInfoService;
import io.renren.modules.pullin.service.PullOutService;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/hello")
public class StuInfoController {
  @Autowired
  StuInfoService stuInfoService;
  @Autowired
    ElectiveCourseService electiveCourseService;

    @RequestMapping("/{scid}/GetStuInfo")
    public StudentInfo GetStuInfo(@PathVariable("scid") String scid){
     StudentInfo studentInfo=stuInfoService.GetStuInfo(scid);
     return studentInfo;
    }
    //临时代码用来更新密码
    @RequestMapping("/UpdatePassword")
    public void UpdatePassword(){
        String salt= RandomString.getRandomString(20);
        String password=new Sha256Hash("123456", salt).toHex();
        stuInfoService.UpdatePassword(salt,password);
    }
    //临时代码，用来放教师用户
    @RequestMapping("/TeacherUser")
    public void TeacherUser(){
        List<TeacherUser> TU=stuInfoService.findTeacherInfo();
        int i=1;
        for(TeacherUser t:TU){
            String salt= RandomString.getRandomString(20);
            String password=new Sha256Hash("123456", salt).toHex();
            stuInfoService.AddStudentLeader(t.getTeacherId(),password,salt,1,1,t.getTeacherName());
            //插入用户角色表
            String usrId=stuInfoService.findUserIdByUserName(t.getTeacherId());
            stuInfoService.InsertUserRole(usrId,"3");
            System.out.println("log:更新用户数据成功，本条第"+i+"条");
            i++;
        }
    }
    //临时代码，用来放学习委员
    @RequestMapping("/StudentLeader")
    public void StudentLeader(){
        String []ID={"201603020114"
              ,"201603020216"
              ,"201603010128"
              ,"201603010228"
              ,"201603010306"
              ,"201603010403"
              ,"201703020103"
              ,"201703010137"
              ,"201703010207"
              ,"201703010302"
              ,"201703010420"
              ,"201703010533"
              ,"201703010601"
              ,"201403180102"
              ,"201403180231"
              ,"201403180348"
              ,"201403180411"
              ,"201503010730"
              ,"201503010837"
              ,"201503010921"
              ,"201503011002"
              ,"201503011101"
              ,"201503011210"
              ,"201603010542"
              ,"201603010614"
              ,"201603010718"
              ,"201603010811"
              ,"201603010937"
              ,"201603011009"
              ,"201603011104"
              ,"201603011204"
              ,"201704050210"
              ,"201704060117"
              ,"201704050117"
              ,"201704040222"
              ,"201704040101"
              ,"201604010222"
              ,"201604010101"
              ,"201604020609"
              ,"201604020718"
              ,"201704020222"
              ,"201704020110"
              ,"201704010107"
              ,"201704010217"
              ,"201704030105"
              ,"201504010601"
              ,"201504010501"
              ,"201604010523"
              ,"201604010404"
              ,"201604030817"
              ,"201604040909"
              ,"201507100428"
               ,"201705010111"
               ,"201705010213"
               ,"201705010316"
               ,"201705010416"
               ,"201605010103"
               ,"201605010220"
               ,"201605010322"
               ,"201605010504"
               ,"201605010611"
               ,"201605010714"
               ,"201605010804"
               ,"201605010903"
               ,"201507100115"
               ,"201507100228"
               ,"201507100309"
               ,"201507100428"
               ,"201403200138"
               ,"201403200204"
               ,"201403200354"
               ,"201403200452"
               ,"201403200550"
               ,"201403200601"
               ,"201403200735"
               ,"201403200809"
               ,"201606010106"
               ,"201606010235"
               ,"201606010310"
               ,"201606010416"
               ,"201606010502"
               ,"201606010610"
               ,"201606010728"
               ,"201606010814"
               ,"201606010930"
               ,"201606011013"
               ,"201606011130"
               ,"201606011210"
               ,"201606011335"
               ,"201606011427"
               ,"201606011517"
               ,"201606011633"
               ,"201606011739"
               ,"201606011817"
               ,"201606011940"
               ,"201606010622"
               ,"201606012001"
               ,"201606012142"
               ,"201606012242"
               ,"201606012341"
               ,"201606012436"
               ,"201606012528"
               ,"201606012429"
               ,"201706010108"
               ,"201706010225"
               ,"201706010316"
               ,"201706010436"
               ,"201706010512"
               ,"201706010601"
               ,"201706010741"
               ,"201706010803"
               ,"201706010931"
               ,"201706011040"
               ,"201706011112"
               ,"201706011239"
               ,"201706011316"
               ,"201706011413"
               ,"201706011533"
               ,"201706011628"
               ,"201706011749"
               ,"201706011806"
               ,"201607010122"
               ,"201607020233"
               ,"201607020108"
               ,"201607020302"
               ,"201607030118"
               ,"201607030217"
               ,"201607030312"
               ,"201607040108"
               ,"201607040235"
               ,"201607040329"
               ,"201607040433"
               ,"201607040511"
               ,"201607040629"
               ,"201607050106"
               ,"201607050232"
               ,"201607050336"
               ,"201607050402"
               ,"201607050516"
               ,"201607010635"
               ,"201707030124"
               ,"201707030210"
               ,"201707030318"
               ,"201707010108"
               ,"201707010208"
               ,"201707010329"
               ,"201707010434"
               ,"201707010542"
               ,"201707040121"
               ,"201707040216"
               ,"201707040318"
               ,"201707050134"
               ,"201707050203"
               ,"201707050305"
               ,"201707020102"
               ,"201707020211"
               ,"201707020333"
               ,"201608010135"
               ,"201608010234"
               ,"201608010328"
               ,"201608010401"
               ,"201608010531"
               ,"201608010631"
               ,"201608010723"
               ,"201608010811"
               ,"201608010936"
               ,"201608011038"
               ,"201608011105"
               ,"201608011220"
               ,"201608011312"
               ,"201708010124"
               ,"201708010259"
               ,"201708010321"
               ,"201708010424"
               ,"201708010531"
               ,"201708010605"
               ,"201708010730"
               ,"201708010833"
               ,"201708010916"
               ,"201708011013"
               ,"201609040102"
               ,"201609040226"
               ,"201609030132"
               ,"201609010119"
               ,"201609010223"
               ,"201609020104"
               ,"201709040113"
               ,"201709040238"
               ,"201709030112"
               ,"201709030229"
               ,"201709010122"
               ,"201709010222"
               ,"201709010308"
               ,"201709020133"
               ,"201709020221"
               ,"201610020101"
               ,"201610020222"
               ,"201610020350"
               ,"201610030116"
               ,"201610060106"
               ,"201610010108"
               ,"201610010222"
               ,"201610050114"
               ,"201610050217"
               ,"201610040114"
               ,"201610070133"
               ,"201610070230"
               ,"201610070303"
               ,"201610070411"
               ,"201610070511"
               ,"201610070624"
               ,"201610070731"
               ,"201710010135"
               ,"201710010210"
               ,"201710010335"
               ,"201710070130"
               ,"201710070217"
               ,"201710070335"
               ,"201710070409"
               ,"201710070534"
               ,"201710070602"
               ,"201710040142"
               ,"201710040224"
               ,"201710030143"
               ,"201710060136"
               ,"201710080131"
               ,"201710080231"
               ,"201710080339"
               ,"201403190122"
               ,"201513090144"
               ,"201611020314"
               ,"201611020418"
               ,"201611010104"
               ,"201611010233"
               ,"201611020109"
               ,"201611030121"
               ,"201611040119"
               ,"201711010134"
               ,"201711010330"
               ,"201711020116"
               ,"201711030124"
               ,"201711030222"
               ,"201711030328"
               ,"201711030418"
               ,"201711040101"
        };
        for(int i=0;i<ID.length;i++){
           String userID=electiveCourseService.queryUserId(ID[i]);
            List<String> u=electiveCourseService.queryUserRoleId(ID[i]);
           if(u.size()==0) {
               electiveCourseService.insertUserRole(userID, "2");
           }
       }



    }

    @RequestMapping("/insertStudent")
    public void insertStudent()
    {
        stuInfoService.insertStudent();
    }


}
